
var STip = ZFT.Util.STip,
    Ajax = ZFT.Util.Ajax,
    Pagination = require("COMMON/modules/pagination-x/v1.0"),
    ParseTemplate = ZFT.Util.ParseTemplate,
    Template = {
        resultList: ParseTemplate(require("./list.xtpl")),
    };
var Main = ZFT.Util.Class({
    container: $("body"),
    init: function () {
        var _this = this,
            pagination = _this.pagination = new Pagination({
                container: $(".paginationWrap"),
                count: 5,
                showTotal: true,
                jump: true,
                filter: true
            });
        pagination.on("page.switch", function (toPage, currentPage, totalPage) {
            pagination.render({ current: currentPage, toPage: toPage }),
                _this.getResultList(toPage);
        });
        _this.getResultList(1);
        _this.initDatepicker();
        $("#getResult").on("click", function () {
            _this.getResultList(1);
        });
    },
    getResultList: function (toPage) {
        if (!toPage) toPage = 1;
        var _this = this,
            pagination = $(".paginationWrap"),
            pageSize = pagination.attr("data-size"),
            tbody = $("#tbody"),
            param = {
                begin: $("#beginDate").val(),
                end: $("#endDate").val(),
                type: $("#eventType").val(),
                source: $("#notifyMethod").val(),
                result: $("#result").val(),
                page: toPage,
                pageSize: pageSize ? pageSize : 10
            };
        Ajax("/r/File_getReconResult", {
            type: "POST",
            dataType: "json",
            params: param,
            loading: function () {
                pagination.hide();
                var loading = '<tr><td colspan="8">正在加载,请稍后...</td></tr>'
                tbody.html(loading);
            },
            success: function (res) {
                if (res.code == 200) {
                    var data = res.data;
                    var resultList = Template.resultList({ data: data.list });
                    tbody.html(resultList);
                    _this.downloadTemplate();
                    _this.pagination.render({ current: toPage, toPage: toPage, total: data.total })
                } else {
                    tbody.html('<tr><td colspan="8">' + res.msg + '</td></tr>')
                }
            }
        })
    },
    //下载对账错误文件
    downloadTemplate: function () {
        var _this = this;
        $(".btn-down").on("click", function (e) {
            var tarBtn = $(e.currentTarget),
                tarUrl = tarBtn.attr("data-href");
            window.open(tarUrl, "_self");
        })
    },
     //初始化日历插件
    initDatepicker: function () {
        $("#beginDate").datepicker({
            format: "yyyy-mm-dd",
            maxViewMode: 2,
            language: "zh-CN",
            autoclose: true
        });
        $('#endDate').datepicker({
            format: "yyyy-mm-dd",
            maxViewMode: 2,
            language: "zh-CN",
            autoclose: true
        });
    },
})

$(function () {
    new Main()
})